package com.inspur.myapplication.util;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

/**
 * Created by Administrator on 2020/11/19.
 */

public class ShoppingDbHelper extends SQLiteOpenHelper {
    private static final String DB_NAME="myshopping.db";

    public ShoppingDbHelper(Context context){
        super(context,DB_NAME,null,2);
    }

    @Override
    public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {
        //sqLiteDatabase.execSQL("");
        //在本方法中进行数据库的升级操作
        upgrade2(sqLiteDatabase);
    }

    private void upgrade2(SQLiteDatabase sqLiteDatabase){
        sqLiteDatabase.execSQL("create table goodstb (goodsid integer primary key, goodstitle text,price real,photo text,category text)");
        sqLiteDatabase.execSQL("insert into goodstb(goodsid,goodstitle,price,photo,category)values(2,'goods2',110,'https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=1541231763,2897362241&fm=26&gp=0.jpg','fangzhi')");
        sqLiteDatabase.execSQL("insert into goodstb(goodsid,goodstitle,price,photo,category)values(1,'goods1',100,'https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=1541231763,2897362241&fm=26&gp=0.jpg','shipin')");
    }

    @Override
    public void onCreate(SQLiteDatabase sqLiteDatabase) {
        createUserModule(sqLiteDatabase);
        createGoodsCartModule(sqLiteDatabase);
        createGoodsModule(sqLiteDatabase);
    }

    private void createUserModule(SQLiteDatabase sqLiteDatabase){
        sqLiteDatabase.execSQL("create table userInfotb(userid integer primary key autoincrement,username text,password text)");
        sqLiteDatabase.execSQL("insert into userInfotb(username,password)values('admin','123456')");
    }

    private void createGoodsModule(SQLiteDatabase sqLiteDatabase){

    }

    private void createGoodsCartModule(SQLiteDatabase sqLiteDatabase){

    }


}
